package com.kun.music.controller;

import com.alibaba.fastjson.JSONObject;
import com.kun.music.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author fangkun
 * @create 2022-12-21-11:29
 */
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;


    @PostMapping("/admin/login/status")
    public Object login(HttpServletRequest request, HttpSession session){

        JSONObject object = new JSONObject();

        String name = request.getParameter("name");
        String password = request.getParameter("password");

        boolean res = adminService.login(name,password);

        if (res){
            object.put("code",1);
            object.put("msg","登录成功");
            session.setAttribute("name",name);
            return object;
        }else {
            object.put("code",0);
            object.put("msg","用户名或密码错误");
            return object;
        }
    }
}
